package xiaye.mycrawler;

import java.io.IOException;

import org.apache.http.*;
import org.apache.http.client.*;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.*;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.*;
import org.apache.http.util.EntityUtils;


public class HttpFetcher {
	public static void main(String[] args){
		HttpParams params = new BasicHttpParams();
		params.setParameter("http.useragent", "Mozzila");
		HttpClient httpClient = new DefaultHttpClient(params);
		HttpContext context = new BasicHttpContext();
		HttpGet get = new HttpGet("http://sina.com.cn/");
		try {
			HttpResponse response = httpClient.execute(get, context);
			System.out.println(context.getAttribute(ExecutionContext.HTTP_TARGET_HOST));
			
			HttpEntity entity = response.getEntity();
			if (entity != null){
				System.out.println(EntityUtils.toByteArray(entity));
			}
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
